@@ -24,7 +24,7 @@ module Agents |
||
24 | 24 |
|
25 | 25 |
* If the Event contains a `url` key, that URL will be fetched. |
26 | 26 |
* For more control, you can set the `url_from_event` option and it will be used as a Liquid template to generate the url to access based on the Event. |
27 |
- * If you set `event_data_path` to the [JSONPath](http://goessner.net/articles/JsonPath/) of content in the Event, that will be used directly without fetching any URL. |
|
27 |
+ * If you set `data_from_event` to the [JSONPath](http://goessner.net/articles/JsonPath/) of content in the Event, that will be used directly without fetching any URL. |
|
28 | 28 |
* If you specify `merge` for the `mode` option, Huginn will retain the old payload and update it with the new values. |
29 | 29 |
|
30 | 30 |
# Supported Document Types |
@@ -145,7 +145,7 @@ module Agents |
||
145 | 145 |
|
146 | 146 |
def validate_options |
147 | 147 |
# Check for required fields |
148 |
- errors.add(:base, "either url, url_from_event, or event_data_path are required") unless options['url'].present? || options['url_from_event'].present? || options['event_data_path'].present? |
|
148 |
+ errors.add(:base, "either url, url_from_event, or data_from_event are required") unless options['url'].present? || options['url_from_event'].present? || options['data_from_event'].present? |
|
149 | 149 |
errors.add(:base, "expected_update_period_in_days is required") unless options['expected_update_period_in_days'].present? |
150 | 150 |
validate_extract_options! |
151 | 151 |
|
@@ -331,18 +331,16 @@ module Agents |
||
331 | 331 |
interpolate_with(event) do |
332 | 332 |
existing_payload = interpolated['mode'].to_s == "merge" ? event.payload : {} |
333 | 333 |
|
334 |
- if event_data_path = options['event_data_path'].presence |
|
335 |
- data = Utils.value_at(event.payload, interpolate_options(event_data_path)) |
|
334 |
+ if data_from_event = options['data_from_event'].presence |
|
335 |
+ data = interpolate_options(data_from_event) |
|
336 | 336 |
if data.present? |
337 | 337 |
handle_event_data(data, event, existing_payload) |
338 | 338 |
else |
339 |
- error "No data was found in the Event payload at the JSONPath #{interpolate_options(event_data_path)}", inbound_event: event |
|
339 |
+ error "No data was found in the Event payload using the template #{data_from_event}", inbound_event: event |
|
340 | 340 |
end |
341 | 341 |
else |
342 | 342 |
url_to_scrape = |
343 |
- if event_data_path = options['event_data_path'].presence |
|
344 |
- interpolate_options(event_data_path) |
|
345 |
- elsif url_template = options['url_from_event'].presence |
|
343 |
+ if url_template = options['url_from_event'].presence |
|
346 | 344 |
interpolate_options(url_template) |
347 | 345 |
else |
348 | 346 |
event.payload['url'] |
@@ -853,7 +853,7 @@ fire: hot |
||
853 | 853 |
end |
854 | 854 |
end |
855 | 855 |
|
856 |
- describe "with a event_data_path" do |
|
856 |
+ describe "with a data_from_event" do |
|
857 | 857 |
describe "with json data" do |
858 | 858 |
before do |
859 | 859 |
@event = Event.new |
@@ -868,7 +868,7 @@ fire: hot |
||
868 | 868 |
|
869 | 869 |
@checker.options = @valid_options.merge( |
870 | 870 |
'type' => 'json', |
871 |
- 'event_data_path' => 'some_object.some_data', |
|
871 |
+ 'data_from_event' => '{{ some_object.some_data }}', |
|
872 | 872 |
'extract' => { |
873 | 873 |
'value' => { 'path' => 'hello' } |
874 | 874 |
} |
@@ -893,14 +893,14 @@ fire: hot |
||
893 | 893 |
|
894 | 894 |
it "should output an error when nothing can be found at the path" do |
895 | 895 |
@checker.options = @checker.options.merge( |
896 |
- 'event_data_path' => 'some_object.mistake' |
|
896 |
+ 'data_from_event' => '{{ some_object.mistake }}' |
|
897 | 897 |
) |
898 | 898 |
|
899 | 899 |
expect { |
900 | 900 |
@checker.receive([@event]) |
901 | 901 |
}.to_not change { Event.count } |
902 | 902 |
|
903 |
- expect(@checker.logs.last.message).to match(/No data was found in the Event payload at the JSONPath some_object.mistake/) |
|
903 |
+ expect(@checker.logs.last.message).to match(/No data was found in the Event payload using the template {{ some_object\.mistake }}/) |
|
904 | 904 |
end |
905 | 905 |
|
906 | 906 |
it "should output an error when the data cannot be parsed" do |
@@ -928,7 +928,7 @@ fire: hot |
||
928 | 928 |
|
929 | 929 |
@checker.options = @valid_options.merge( |
930 | 930 |
'type' => 'html', |
931 |
- 'event_data_path' => 'some_object.some_data', |
|
931 |
+ 'data_from_event' => '{{ some_object.some_data }}', |
|
932 | 932 |
'extract' => { |
933 | 933 |
'title' => { 'css' => ".title", 'value' => ".//text()" }, |
934 | 934 |
'body' => { 'css' => "div span.body", 'value' => ".//text()" } |